Imports cmplib01

Public Class frmAddElementType
    Inherits System.Windows.Forms.Form

    Private ptrNewItem As ElementType
    Private ptrElementClasses As ElementClasses
    Private c_Module As String = "frmAddElementType"

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlElementClasses As System.Windows.Forms.Panel
    Friend WithEvents lblElementClasses As System.Windows.Forms.Label
    Friend WithEvents txtElementTypeName As System.Windows.Forms.TextBox
    Friend WithEvents cboElementTypeClass As System.Windows.Forms.ComboBox
    Friend WithEvents txtElementTypeDescription As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents lblElementName As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents lblPointValue As System.Windows.Forms.Label
    Friend WithEvents txtElementTypePointValue As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.pnlElementClasses = New System.Windows.Forms.Panel()
        Me.lblPointValue = New System.Windows.Forms.Label()
        Me.txtElementTypePointValue = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.lblElementName = New System.Windows.Forms.Label()
        Me.txtElementTypeDescription = New System.Windows.Forms.TextBox()
        Me.txtElementTypeName = New System.Windows.Forms.TextBox()
        Me.cboElementTypeClass = New System.Windows.Forms.ComboBox()
        Me.lblElementClasses = New System.Windows.Forms.Label()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.pnlElementClasses.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlElementClasses
        '
        Me.pnlElementClasses.BackColor = System.Drawing.SystemColors.ControlLight
        Me.pnlElementClasses.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlElementClasses.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblPointValue, Me.txtElementTypePointValue, Me.Label2, Me.lblElementName, Me.txtElementTypeDescription, Me.txtElementTypeName, Me.cboElementTypeClass, Me.lblElementClasses})
        Me.pnlElementClasses.Location = New System.Drawing.Point(8, 8)
        Me.pnlElementClasses.Name = "pnlElementClasses"
        Me.pnlElementClasses.Size = New System.Drawing.Size(256, 256)
        Me.pnlElementClasses.TabIndex = 4
        '
        'lblPointValue
        '
        Me.lblPointValue.Location = New System.Drawing.Point(7, 206)
        Me.lblPointValue.Name = "lblPointValue"
        Me.lblPointValue.Size = New System.Drawing.Size(184, 16)
        Me.lblPointValue.TabIndex = 15
        Me.lblPointValue.Text = "Element Type Point Value"
        '
        'txtElementTypePointValue
        '
        Me.txtElementTypePointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtElementTypePointValue.Location = New System.Drawing.Point(7, 230)
        Me.txtElementTypePointValue.Name = "txtElementTypePointValue"
        Me.txtElementTypePointValue.Size = New System.Drawing.Size(240, 20)
        Me.txtElementTypePointValue.TabIndex = 2
        Me.txtElementTypePointValue.Text = "0"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(184, 16)
        Me.Label2.TabIndex = 9
        Me.Label2.Text = "Description"
        '
        'lblElementName
        '
        Me.lblElementName.Location = New System.Drawing.Point(8, 56)
        Me.lblElementName.Name = "lblElementName"
        Me.lblElementName.Size = New System.Drawing.Size(184, 16)
        Me.lblElementName.TabIndex = 8
        Me.lblElementName.Text = "Element Type Name"
        '
        'txtElementTypeDescription
        '
        Me.txtElementTypeDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtElementTypeDescription.Location = New System.Drawing.Point(8, 128)
        Me.txtElementTypeDescription.Multiline = True
        Me.txtElementTypeDescription.Name = "txtElementTypeDescription"
        Me.txtElementTypeDescription.Size = New System.Drawing.Size(240, 72)
        Me.txtElementTypeDescription.TabIndex = 1
        Me.txtElementTypeDescription.Text = "New Element Type Description"
        '
        'txtElementTypeName
        '
        Me.txtElementTypeName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtElementTypeName.Location = New System.Drawing.Point(8, 80)
        Me.txtElementTypeName.Name = "txtElementTypeName"
        Me.txtElementTypeName.Size = New System.Drawing.Size(240, 20)
        Me.txtElementTypeName.TabIndex = 0
        Me.txtElementTypeName.Text = "New Element"
        '
        'cboElementTypeClass
        '
        Me.cboElementTypeClass.Location = New System.Drawing.Point(8, 32)
        Me.cboElementTypeClass.Name = "cboElementTypeClass"
        Me.cboElementTypeClass.Size = New System.Drawing.Size(240, 21)
        Me.cboElementTypeClass.TabIndex = 5
        Me.cboElementTypeClass.TabStop = False
        Me.cboElementTypeClass.Text = "(None)"
        '
        'lblElementClasses
        '
        Me.lblElementClasses.Location = New System.Drawing.Point(8, 8)
        Me.lblElementClasses.Name = "lblElementClasses"
        Me.lblElementClasses.Size = New System.Drawing.Size(184, 16)
        Me.lblElementClasses.TabIndex = 4
        Me.lblElementClasses.Text = "Select Class"
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(184, 272)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "OK"
        '
        'frmAddElementType
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(272, 304)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnOK, Me.pnlElementClasses})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmAddElementType"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Element Type"
        Me.pnlElementClasses.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef NewItem As ElementType, ByVal ElClasses As ElementClasses)
        Me.new()

        ptrNewItem = NewItem
        ptrElementClasses = ElClasses

        ' if there are no classes, close this form
        If ptrElementClasses.Count = 0 Then
            MessageBox.Show("There are no Element Classes defined. You must have at least one Element Class defined.", "No Element Classes")
            Me.Hide()
        End If

        ListProperties()

    End Sub

    Private Sub ListProperties()
        Try
            Dim elClasso As ElementClass
            cboElementTypeClass.Items.Add("(None Selected)")
            ' set up classes
            For Each elClasso In ptrElementClasses
                cboElementTypeClass.Items.Add(elClasso)
            Next
            ' select class for this type
            If ptrNewItem.ElementClassName = "(None Selected)" Then
                cboElementTypeClass.Text = "(None Selected)"
            Else
                cboElementTypeClass.Text = ptrNewItem.ElementClassName
            End If
            'properties here
            txtElementTypeName.Text = ptrNewItem.ElementTypeName
            txtElementTypeDescription.Text = ptrNewItem.ElementDescription
            txtElementTypePointValue.Text = ptrNewItem.ElementPointValue

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            If cboElementTypeClass.Text = "(None Selected)" Then
                MessageBox.Show("You must select an Element Class for this type.", "Select Element Class")
                Exit Sub
            End If
            ptrNewItem.ElementClassName = cboElementTypeClass.Text
            ptrNewItem.ElementDescription = txtElementTypeDescription.Text
            ptrNewItem.ElementTypeName = txtElementTypeName.Text
            ptrNewItem.ElementPointValue = CInt(txtElementTypePointValue.Text)
            Me.Hide()
        Catch badEx As InvalidCastException
            MessageBox.Show("Element Point Value must be numerical.", "Invalid Point Value")
            Exit Sub
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

End Class
